﻿-var isexcel = ViewData.ContainsKey("excel")
-var table = ViewData["DataTable"] as DataTable
=HTMLHelper.HiddenInput("tablecontroller",ViewData["Controller"])
-var curUserId = 0
-var columnsCount = table.Columns.Count 
-var rowsCount = table.Rows.Count
-for(int i = 0; i < rowsCount; ++i)
  -var dr = table.Rows[i]
  -curUserId = Convert.ToInt32(dr["UserId"])
  %table.data{width="100%", border=(isexcel) ? "1" : "0"}
    %tr
      %th{colspan="4"}
        =dr["UserName"].ToString().ToUpper()
    %tr
      -for(int j = 2; j < columnsCount; ++j)
        %th
          =table.Columns[j].Caption
      -do
        -dr=table.Rows[i]
        %tr
          -for(int k = 2; k < columnsCount; ++k)
            %td{width="25%", class=(k == columnsCount-1) ? "last" : ""}
              =dr[k].ToString()                           
      -while(++i < rowsCount && curUserId == Convert.ToInt32(table.Rows[i]["UserId"]))
      -i--        
  %br